package com.alibaba.dingtalk.openapi.newmessage.delivery;/*/*/

import com.alibaba.dingtalk.openapi.exception.ApiRuleException;
import com.alibaba.dingtalk.openapi.newmessage.entity.Msg;
import com.alibaba.dingtalk.openapi.newmessage.utils.DeliveryCheckUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 发送工作通知消息
 * @author 魏荣杰
 * @date 2019/3/21 19:57
 * @since v1.0
 * @version v1.0
 */
@Setter
@Getter
@ToString
public class CorpConversationSendMsgDelivery extends AbstractDelivery{
    private static final long serialVersionUID = -4493544615935153195L;

    /**
     * 应用agentId
     */
    private Long agentId;

    /**
     * 	接收者的用户userid列表，最大列表长度：100, 例如：3541561,454564  中间用英文逗号隔开
     */
    private String useridList;

    /**
     * 接收者的部门id列表，最大列表长度：20,  接收者是部门id下(包括子部门下)的所有用户   例如：3541561,454564  中间用英文逗号隔开
     */
    private String deptIdList;
    /**
     * 是否发送给企业全部用户
     */
    private Boolean toAllUser;

    /**
     * 消息内容 json对象
     */
    private Msg msg;

    public CorpConversationSendMsgDelivery() {
        //默认不发给企业全部用户
        this.toAllUser = false;
    }

    @Override
    public JSONObject toJsonObject() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("agent_id", this.agentId);
        jsonObject.put("userid_list", this.useridList);
        jsonObject.put("dept_id_list", this.deptIdList);
        jsonObject.put("to_all_user", this.toAllUser);
        jsonObject.put("msg", this.msg.toJsonObject());
        return jsonObject;
    }

    @Override
    public void check() throws ApiRuleException {
        DeliveryCheckUtils.checkNotEmpty(agentId, "agentId");
        DeliveryCheckUtils.checkMaxListSize(deptIdList, 500, "deptIdList");
        DeliveryCheckUtils.checkMaxListSize(useridList, 5000, "useridList");
    }
}
